﻿using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;

namespace Game.FlowField.Burst
{
    [BurstCompile]
    public struct BlockRemovingJob : IJob
    {
        [ReadOnly]
        public int2 MapSize;

        /// <summary>
        /// Input
        /// </summary>
        [ReadOnly]
        public NativeArray<int2> RemovingGridIndexPairs;

        /// <summary>
        /// Output
        /// </summary>
        [WriteOnly]
        public NativeArray<bool> GridIsBlocks;

        [BurstCompile]
        public void Execute()
        {
            var length = RemovingGridIndexPairs.Length;
            for (int i = 0; i < length; i++)
            {
                var removingIndexPair = this.RemovingGridIndexPairs[i];
                if (!MapDataUtil.IsInsideMap(removingIndexPair, this.MapSize))
                    continue;

                var index = MapDataUtil.ConvertIndex2D2Index(removingIndexPair, this.MapSize);
                this.GridIsBlocks[index] = false;
            }
        }
    }
}